#
# Copyright (C) 2017-2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#

set(BUILTIN_KERNELS_SIMULATION_SRCS
  ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
  ${CMAKE_CURRENT_SOURCE_DIR}/opencl_c.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/opencl_c.h
  ${CMAKE_CURRENT_SOURCE_DIR}/scheduler_simulation.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/scheduler_simulation.inl
  ${CMAKE_CURRENT_SOURCE_DIR}/scheduler_simulation.h
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

string(REPLACE "/WX" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "-Werror[^ \t\n]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-Wsometimes-uninitialized" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-Wsign-compare" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-Wunused-variable" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-everything")
endif()

if(COMPILER_SUPPORTS_CXX11)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

if(NOT MSVC)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fPIC")
endif()

macro(macro_for_each_gen)
  list(APPEND DEFAULT_GEN_PLATFORMS_DEFITIONS DEFAULT_${GEN_TYPE}_PLATFORM=${DEFAULT_SUPPORTED_${GEN_TYPE}_PLATFORM})
  if(${SUPPORT_DEVICE_ENQUEUE_${GEN_TYPE}})
    list(APPEND BUILTIN_KERNELS_SIMULATION_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/${GEN_TYPE_LOWER}/scheduler_simulation_${GEN_TYPE_LOWER}.cpp)
  endif()
endmacro()

apply_macro_for_each_gen("SUPPORTED")

add_library(${BIKSIM_LIB_NAME} OBJECT EXCLUDE_FROM_ALL ${BUILTIN_KERNELS_SIMULATION_SRCS})
target_include_directories(${BIKSIM_LIB_NAME} BEFORE PRIVATE
  ${ENGINE_NODE_DIR}
  ${NEO__GMM_INCLUDE_DIR}
  ${KHRONOS_HEADERS_DIR}
  ${KHRONOS_GL_HEADERS_DIR}
  ${NEO__IGC_INCLUDE_DIR}
  ${THIRD_PARTY_DIR}
)
set_target_properties(${BIKSIM_LIB_NAME} PROPERTIES FOLDER "built_ins")
target_compile_definitions(${BIKSIM_LIB_NAME} PUBLIC ${SUPPORTED_GEN_FLAGS_DEFINITONS} ${DEFAULT_GEN_PLATFORMS_DEFITIONS} MOCKABLE_VIRTUAL=)
